/*
package com.unionpay.upyzt.spring.example;

import com.google.gson.Gson;
import com.unionpay.upyzt.model.BalanceAcct;
import com.unionpay.upyzt.net.APIResource;
import com.unionpay.upyzt.net.HttpContent;
import com.unionpay.upyzt.resp.BalanceAcctResp;
import com.unionpay.upyzt.spring.example.config.UpyztProperties;
import com.unionpay.upyzt.util.StringUtils;
import com.unionpay.upyzt.util.UpyztSignature;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.Charset;
import java.util.Collections;
import java.util.Locale;

*/
/**
 * @author yf.zhao
 * @version 1.0
 * @since 2020/8/27
 *//*

@Slf4j
@Component
@Profile("test")
public class RestExampleRunner implements CommandLineRunner {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private UpyztProperties upyztProperties;

    @Autowired
    private Gson gson;

    @Override
    public void run(String... args) throws Exception {
//        String apiUrl = upyztProperties.getApiBase() + "/v1/balance_accts/2002512507915798533";
//        HttpHeaders headers = new HttpHeaders();
//        headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
//        headers.setAcceptCharset(Collections.singletonList(Charset.defaultCharset()));
//        headers.setAcceptLanguage(Locale.LanguageRange.parse("zh-CN"));
//        headers.set("Authorization", authorization(HttpMethod.GET, "/v1/balance_accts/2002512507915798533", null));
//        HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(headers);
//        ResponseEntity<String> resp = restTemplate.exchange(apiUrl, HttpMethod.GET, request, String.class);
//        if (HttpStatus.OK.equals(resp.getStatusCode())) {
//            BalanceAcctResp balanceAcctResp = APIResource.getGson().fromJson(resp.getBody(), BalanceAcctResp.class);
//            balanceAcctResp.setRequestId(resp.getHeaders().getFirst("Request-Id"));
//            log.info("------- 电子账簿查询 ------- {} ", gson.toJson(balanceAcctResp));
//        } else {
//            log.error("request error {} ", resp.getBody());
//        }

        BalanceAcctResp balanceAcctResp = BalanceAcct.retrieveById("2002512507915798533");
        log.info("------- 电子账簿查询 ------- {} ", gson.toJson(balanceAcctResp));
    }

    private String authorization(HttpMethod httpMethod, String apiUrl, HttpContent content) {
        String rootMchId = upyztProperties.getRootMchId();
        String signPrivateKey = upyztProperties.getSignPrivateKey();
        String currentTimeStr = StringUtils.currentTimeStamp();
        String nonceStr = StringUtils.randomAlphanumeric(32);
        String signData = httpMethod.name() + "\n" + apiUrl + "\n" + currentTimeStr + "\n" + nonceStr + "\n";
        if (content != null) {
            signData += content.getContent();
        }
        String sign = UpyztSignature.sign(signData, signPrivateKey, APIResource.CHARSET.name());
        if (sign == null) {
            throw new RuntimeException("未设置正确的 Upyzt.signPrivateKey，无法生成签名");
        }
        return "UNIONPAY1-SHA256-RSA root_mch_id=" + rootMchId +
                ",nonce_str=" + nonceStr +
                ",timestamp=" + currentTimeStr +
                ",signature=" + sign;
    }
}
*/
